package com.zhiqiang.gameserver.nettydemo.demo;

import com.zhiqiang.gameserver.constant.R;
import com.zhiqiang.gameserver.entity.ZQGameServerEntity;
import com.zhiqiang.gameserver.proto.gameServerUserInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author YAO
 */
public class loginClientHandler extends ChannelInboundHandlerAdapter {
    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ZQGameServerEntity entity = new ZQGameServerEntity();
        gameServerUserInfo.ReqUserLogin.Builder builder = gameServerUserInfo.ReqUserLogin.newBuilder();
//        builder.setAccount(526571646);
//        builder.setPassword("123456");
//        builder.setServerw("1服");
        entity.setLen(builder.build().toByteArray().length+ R.EncoderAndDecoder.HEADER_LENGTH);
        entity.setMsgType(R.MessageType.REQUSERLOGIN);
        entity.setSeq(199);
        entity.setUid(1001);
        entity.setResult(123);
        entity.setV6(200);
        entity.setV7(0);
        entity.setV8(0);
        entity.setV9(0);
        entity.setV10(0);
        entity.setV11(0);
        entity.setV12(0);
        entity.setData(builder.build().toByteArray());
        ctx.writeAndFlush(entity);

    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.err.println(msg.toString());

    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        cause.printStackTrace();
        ctx.close();
    }
}
